using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.ObjectBuilder;
using GC2.ExceptionHandler;
using GC2.ExceptionHandler.Services;
using GC2.Entities.Seguridad;

namespace GC2.DataAccess.DASeguridad
{
    public class DASuperMenu
    {
        private Database _database;        // Objeto DataBase del Data Access Application Block

        #region Propiedades miembro
        /// <summary>
        /// Seteo la propiedad _database de la clase.
        /// </summary>
        private Database DataBase
        {
            get { return _database; }
            set { _database = value; }
        }
        #endregion

        #region Constructor
        /// <summary>
        /// Contructor de la clase sin parametro. Crea un objeto DataBase
        /// del Data AppBlock tomando el defaultDatabase del app.config.
        /// </summary>
        //public AplicacionesDataAccess()
        //{
        //    this.DataBase = DatabaseFactory.CreateDatabase();
        //}
        #endregion

        #region DASuperMenuGetAll
        /// <summary>
        /// Devuelve lista de items de menu que puede ver un usuario supervisor
        /// </summary>
        /// <param name="Connection"></param>
        /// <param name="RemitosDet"></param>
        /// <returns><List>SuperMenu</List></returns>
        public List<SuperMenu> DASuperMenuGetAll(string Connection, SuperMenu menu)
        {
            try
            {
                this.DataBase = DatabaseFactory.CreateDatabase(Connection);
                DbCommand cmd = DataBase.GetStoredProcCommand("SuperMenu_GetAll");

                List<SuperMenu> listaMenu = new List<SuperMenu>();
                using (cmd)
                {
                    DataBase.AddInParameter(cmd, "@Id_Usuario", DbType.Int16, menu.Id_Usuario);

                    IDataReader Odbreader = DataBase.ExecuteReader(cmd);
                    while (Odbreader.Read())
                    {
                        SuperMenu oMenu = new SuperMenu();

                        oMenu.Id_Usuario = (int)Odbreader["Id_Usuario"];
                        oMenu.Menu = (int)Odbreader["Menu"];
                        oMenu.IdTarea = (int)Odbreader["IdTarea"];
                        oMenu.Tarea = (string)Odbreader["Tarea"];
                        oMenu.Ver = (int)Odbreader["Ver"];

                        listaMenu.Add(oMenu);
                    }
                    Odbreader.Close();
                    Odbreader.Dispose();
                }
                return listaMenu;
            }
            catch (SqlException sql_ex)
            {
                ExceptionSQL exNew = new ExceptionSQL();
                throw new System.Exception(exNew.exSQL(sql_ex.ToString()).ToString());
            }
            catch (Exception ex)
            {
                ExceptionDAL exNew = new ExceptionDAL();
                throw new System.Exception(exNew.exDAL(ex.ToString()).ToString());
            }
        }
        #endregion
    }
}
